<template>
  <div v-if="userList.data">
    <el-table :data="userList.data" border style="width: 100%">
      <el-table-column
        v-for="(item ,index) in returnDatas.tableLable"
        align="center"
        header-align="center"
        :prop="item.prop"
        :label="item.label"
        :key="index"
      ></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="dlgType(1,scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { $Http } from '@/plugins/axios'
import store from '@/store/index'
import { znk } from '@/assets/util/public'
export default {
  layout: 'admin',
  data() {
    return {
      // userList: {
      // },
      returnDatas: {
        apiData: {}, // 当前列数据
        tableLable: [
          // 表格字段
          {
            label: '姓名',
            prop: 'username'
          },
          {
            label: '邮箱',
            prop: 'email'
          },
          {
            label: '创建时间',
            prop: 'create_time'
          },
        ],
        tableData: {}, // 表格数据
        defaultProps: {
          children: 'children',
          label: 'name'
        },
      }
    }
  },
  async asyncData({ req, res }) {
    return $Http('get', 'api/admin/user/userList', null, req).then((data) => {
      return { userList: data }
    })
  },
  methods: {
    listPage() {
      $Http('get', 'api/admin/user/userList').then((data) => {
        this.userList = data
      })
    },
    // 表格元素过滤
    dlgType(type, apiData) {
      $Http('post', 'api/admin/user/delUser', { id: apiData.id }).then((data) => {
        console.log('0000', data)
        this.listPage()
      })
      console.log(apiData)
    }
    // filter (r, c) {
    //   if (c.property === 'createTime') {
    //     console.log(this.returnDatas.options)
    //     let type = this.returnDatas.options
    //     let txt = ''
    //     type.forEach(item => {
    //       if (item.id === r.type) {
    //         txt = item.dicName
    //       }
    //     })
    //     return txt
    //   } else if (c.property === 'enabled') {
    //     return r.enabled === true ? '是' : '否'
    //   } else {
    //     return r[c.property]
    //   }
    // },
  },
  watch: {
    '$route': function () {
      console.log('$route has changed.', this)
    }
  }
}
</script>